package com.yl.myapplication.slice;

import com.yl.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;

public class MainAbilitySlice extends AbilitySlice {

    Text tv2;
    Text tv1;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button btn = (Button) findComponentById(ResourceTable.Id_btn);
        Button btn2 = (Button) findComponentById(ResourceTable.Id_btn2);
        tv1 = (Text) findComponentById(ResourceTable.Id_tv1);
        tv2 = (Text) findComponentById(ResourceTable.Id_tv2);
        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent1 = new Intent();
                intent1.setParam("data", tv1.getText().toString().trim());
                presentForResult(new HomeAbilitySlice(), intent1, 123);
            }
        });

        btn2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {

                //第一种跳转
//                Intent intent = new Intent();
//                Operation operation = new Intent.OperationBuilder()
//                        .withDeviceId("")
//                        .withBundleName("com.yl.myapplication")
//                        .withAbilityName("com.yl.myapplication.MyAbility")
//                        .build();
//                intent.setOperation(operation);
//                startAbility(intent);

                //第二种跳转
                startAbility(new Intent().setAction("my"));
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }


    @Override
    protected void onResult(int requestCode, Intent resultIntent) {
        super.onResult(requestCode, resultIntent);
        if (requestCode == 123) {
            String pwd = resultIntent.getStringParam("pwd");
            tv2.setText(pwd);
        }
    }
}
